<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$mydb = new DB();
$type = intval(getvar("type"));
$numStr = "";
$round = "";
switch ($type)
{
    case 0 :
        $sql = "SELECT n1,n2,n3,n4,n5,n6,spec,round FROM lotto WHERE open = '" . date("Y-m-d") . "' LIMIT 0,1";
        $rs = getdb($sql);
        $dataStr = "";
        $msg = "";
        if (!$rs->eof)
        {
            $msg = "OK";
            $numStr = "";
            $numStr .= "\"" . str_pad($rs->f['n1'], 2, "0", STR_PAD_LEFT) . "\"";
            $numStr .= ",\"" . str_pad($rs->f['n2'], 2, "0", STR_PAD_LEFT) . "\"";
            $numStr .= ",\"" . str_pad($rs->f['n3'], 2, "0", STR_PAD_LEFT) . "\"";
            $numStr .= ",\"" . str_pad($rs->f['n4'], 2, "0", STR_PAD_LEFT) . "\"";
            $numStr .= ",\"" . str_pad($rs->f['n5'], 2, "0", STR_PAD_LEFT) . "\"";
            $numStr .= ",\"" . str_pad($rs->f['n6'], 2, "0", STR_PAD_LEFT) . "\"";
            $numStr .= ",\"" . str_pad($rs->f['spec'], 2, "0", STR_PAD_LEFT) . "\"";
            $round = d3($rs->f['round']);
        }
        else
        {
            $msg = "false";
        }
        break;
    case 1 :
        $sql = "SELECT n3,n2,n1,round FROM lotto_3d WHERE open = '" . date("Y-m-d") . "' LIMIT 0,1";
        $rs = getdb($sql);
        $dataStr = "";
        $msg = "";
        if (!$rs->eof)
        {
            $msg = "OK";
            $numStr = "";
            $numStr .= "\"" . $rs->f['n3'] . "\"";
            $numStr .= ",\"" . $rs->f['n2'] . "\"";
            $numStr .= ",\"" . $rs->f['n1'] . "\"";
            $round = $rs->f['round'];
        }
        else
        {
            $msg = "false";
        }
        break;
    case 2 :
        $sql = "SELECT n3,n2,n1,round FROM lotto_3t WHERE open = '" . date("Y-m-d") . "' LIMIT 0,1";
        $rs = getdb($sql);
        $dataStr = "";
        $msg = "";
        if (!$rs->eof)
        {
            $msg = "OK";
            $numStr = "";
            $numStr .= "\"" . $rs->f['n3'] . "\"";
            $numStr .= ",\"" . $rs->f['n2'] . "\"";
            $numStr .= ",\"" . $rs->f['n1'] . "\"";
            $round = $rs->f['round'];
        }
        else
        {
            $msg = "false";
        }
        break;
}
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/plain");
echo "{";
echo "\"msg\":\"" . $msg . "\"";
echo ",\"openNum\":[" . $numStr . "]";
echo ",\"openRound\":\"" . $round . "\"";
echo "}";
?>